package com.czl.module_activity.adapter

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.CommunityResponseBean
import com.czl.module_activity.R
import com.czl.module_activity.databinding.ItemActivityBinding
import com.czl.module_activity.fragment.ActivityListFragment

class ActivityAdapter(private val fragment: ActivityListFragment) :
    BaseQuickAdapter<CommunityResponseBean.Record, BaseDataBindingHolder<ItemActivityBinding>>(
        R.layout.item_activity
    )  {
    override fun convert(
        holder: BaseDataBindingHolder<ItemActivityBinding>,
        item: CommunityResponseBean.Record
    ) {
        holder.dataBinding?.apply {
            data = item
            adapter = this@ActivityAdapter
            executePendingBindings()
        }
    }
    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is CommunityResponseBean.Record){
            fragment.startContainerActivity(
                AppConstants.Router.Activities.F_ACTIVITIES_DETAIL,
                Bundle().apply {
                    putString(
                        AppConstants.BundleKey.ACTIVITY_ID,
                        it.id.toString()
                    )
                })
        }
    })
}